import time


def calc_time(type='s'):
    """
    计算函数运算时间
    :param type: 时间单位
    :return: None
    """

    def decorate(func):
        def wrapper(*args, **kwargs):
            time1 = time.time()
            func(*args, **kwargs)
            time2 = time.time()
            t = time2 - time1
            if type == 'us':
                t = t * 1e6
            elif type == 'ms':
                t = t * 1e3
            elif type == 's':
                pass
            elif type == 'm':
                t = t / 60
            elif type == 'h':
                t = t * 3600
            print('函数名：%s\n参数：args：%s\tkwargs：%s\n执行耗时：%.4f%s\n' % (func.__name__, args, kwargs, t, type))

        return wrapper

    return decorate
